package com.diao.myhub.service.impl;

import com.diao.myhub.cache.AllTagCache;
import com.diao.myhub.service.PublishService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

@Service
@RequiredArgsConstructor
public class PublishServiceImpl implements PublishService {
    private final AllTagCache allTagCache;


    @Override
    public boolean validate(String tags){
        String[] tag = tags.split(",");
        if (tag.length>4){
            return false;
        }
        HashSet<String> tagSet = new HashSet<>();
        for (String t : tag) {
            if (tagSet.contains(t)||!allTagCache.getAllTags().contains(t)){
                return false;
            }else {
                tagSet.add(t);
            }
        }
        return true;
    }
}
